package com.young.springdemo.service.singleton;

//懒汉式单例模式,调用的时候加载
public class LazySingleton {

    private volatile static LazySingleton lazySingleton = null;

    private LazySingleton() {

    }

    //双重锁
    public static LazySingleton getInstance() {
        if (lazySingleton == null) {
            synchronized (LazySingleton.class) {
                if (lazySingleton == null) {
                    lazySingleton = new LazySingleton();
                }
            }
        }
        return lazySingleton;
    }
}
